package com.hdoit.kylin.logical.studentManager.dao.impl;
import java.util.List;

import org.springframework.stereotype.Component;

import com.tennetcn.common.dao.base.IFinderExpression;
import com.tennetcn.common.dao.base.impl.SuperDao;
import com.tennetcn.common.message.PagerModel;
import com.tennetcn.common.utils.FinderExpressionFactory;
import com.alibaba.druid.util.StringUtils;
import com.hdoit.kylin.logical.studentManager.dao.IExcel_headDao;
import com.hdoit.kylin.logical.studentManager.model.Excel_head;
import com.hdoit.kylin.logical.viewmodel.Excel_headSearch;

/**
* @author luozhicheng
* @email
* @createtime 2017年07月18日 20:14:32
* @comment
*/
@Component
public class Excel_headDaoImpl extends SuperDao<Excel_head> implements IExcel_headDao{
	public boolean deleteByExcelId(String excelId){
		IFinderExpression finderExpression=FinderExpressionFactory.createExpression();
		finderExpression.delete()
						.from(Excel_head.class)
						.andWhere("excelId=#{excelId}")
						.setParam("excelId", excelId);
		
		return delete(finderExpression)>0;
	}
	
	@Override
	public List<Excel_head> queryList(Excel_headSearch search,PagerModel pagerModel) {
		IFinderExpression finderExpression=FinderExpressionFactory.createExpression();
		finderExpression.select("*")
						.from(Excel_head.class,"date_head");
		
		finderExpression.addOrderInfoList(getOrderInfoList());
		
		finderExpression = appendExpression(finderExpression, search);						     
		
		return queryList(finderExpression,search);
	}

	private IFinderExpression appendExpression(IFinderExpression finderExpression, Excel_headSearch search) {
		
		if(!StringUtils.isEmpty(search.getExcelId())){
			finderExpression.andWhere("date_head.excelId=#{excelId}")
							.setParam("excelId", search.getExcelId());
		}
		
		return finderExpression;
	}
	
}